import { request } from '@/utils';
import { getRestBaseUrl } from '@/config';

export default class MtGrapTaskService {
  static listMtGrapTaskByPage(params) {
    console.log(params);
    return request({
      url: `${getRestBaseUrl()}/iop/crawlerTaskManagerService/list`,
      method: 'POST',
      data: params,
    });
  }

  static addTask(params) {
    if (params) {
      params.storeId = params.storeId.join(',');
      params.storeName = params.storeName.join(',');
    }
    return request({
      url: `${getRestBaseUrl()}/iop/crawlerTaskManagerService/addTask`,
      method: 'POST',
      data: { params },
    });
  }

  static publishTask(params) {
    if (params) {
      params.storeId = params.storeId.join(',');
      params.storeName = params.storeName.join(',');
    }
    return request({
      url: `${getRestBaseUrl()}/mtGrabTask/publishTask`,
      method: 'POST',
      data: { params },
    });
  }

  static batchPublishTask(params) {
    return request({
      url: `${getRestBaseUrl()}/iop/crawlerTaskManagerService/addTask`,
      method: 'POST',
      data: params,
    });
  }

  static getTaskDetail(params) {
    return request({
      url: `${getRestBaseUrl()}/iop/crawlerTaskManagerService/getTaskDetail`,
      method: 'POST',
      data: params,
    });
  }

  static deleteById(id) {
    return request({
      url: `${getRestBaseUrl()}/mtGrabTask/deleteById/` + id,
      method: 'GET',
      data: null,
    });
  }

  static listMtSuggestAddress(cityName, keyword) {
    return request({
      url: `${getRestBaseUrl()}/mtGrabTask/listMtSuggestAddress`,
      method: 'GET',
      data: {
        cityName: cityName,
        keyword: keyword,
      },
    });
  }

  static listChannelPageMtPoi(poiName, address, cityName, longitude, latitude, pageNum) {
    return request({
      url: `${getRestBaseUrl()}/mtGrabTask/listChannelPageMtPoi`,
      method: 'GET',
      data: {
        poiName: poiName,
        address: address,
        cityName: cityName,
        longitude: longitude,
        latitude: latitude,
        pageNum: pageNum,
      },
    });
  }

  static listSubTask(params) {
    return request({
      url: `${getRestBaseUrl()}/iop/crawlerTaskManagerService/listSubTask`,
      method: 'POST',
      data: params,
    });
  }

  static exportTaskStoreData(taskId) {
    return request({
      url: `${getRestBaseUrl()}/mtGrabTask/exportTaskStoreData`,
      method: 'POST',
      data: 'taskId=' + taskId,
    });
  }

  static exportWeiziSku(params) {
    return request({
      url: `${getRestBaseUrl()}/iop/crawlerTaskManagerService/export`,
      method: 'POST',
      data: params,
    });
  }

  static cancelTask(params) {
    return request({
      url: `${getRestBaseUrl()}/iop/crawlerTaskManagerService/cancelTask`,
      method: 'POST',
      data: params,
    });
  }

  static exportStore(params) {
    return request({
      url: `${getRestBaseUrl()}/iop/crawlerTaskManagerService/exportStore`,
      method: 'POST',
      data: params,
    });
  }

  static checkStoreNames(params) {
    return request({
      url: `${getRestBaseUrl()}/iop/crawlerTaskManagerService/checkStoreNames`,
      method: 'POST',
      data: params,
    });
  }
}
